package com.lottery.ruok.lottrey.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.activity.TransferPayActivity;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by ASUS on 2017/11/11.
 */

public class BankRemittanceAdapter extends BaseAdapter {
    private TransferPayActivity transferPayActivity;
    public BankRemittanceAdapter(TransferPayActivity transferPayActivity){
        this.transferPayActivity = transferPayActivity;
    }

    @Override
    public int getCount() {
        if (transferPayActivity == null || transferPayActivity.getRechargeBankResponses == null|| transferPayActivity.getRechargeBankResponses.size() <= transferPayActivity.bankTransferIndex || transferPayActivity.getRechargeBankResponses.get(transferPayActivity.bankTransferIndex).getData() == null) {
            return 0;
        }
        return transferPayActivity.getRechargeBankResponses.get(transferPayActivity.bankTransferIndex).getData().size();
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view != null) {
            holder = (ViewHolder) view.getTag();
        } else {
            view = LayoutInflater.from(transferPayActivity).inflate(R.layout.charge_transfer_item, null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        }

        holder.bank.setText(transferPayActivity.getRechargeBankResponses.get(transferPayActivity.bankTransferIndex).getData().get(i).getBankname());
        holder.subbank.setText(transferPayActivity.getRechargeBankResponses.get(transferPayActivity.bankTransferIndex).getData().get(i).getBank_son());
        holder.gatheringPerson.setText(transferPayActivity.getRechargeBankResponses.get(transferPayActivity.bankTransferIndex).getData().get(i).getRealname());
        holder.account.setText(transferPayActivity.getRechargeBankResponses.get(transferPayActivity.bankTransferIndex).getData().get(i).getCard_no());
        holder.exchangeRange.setText(transferPayActivity.getRechargeBankResponses.get(transferPayActivity.bankTransferIndex).getData().get(i).getMin_quota() + "〜" + transferPayActivity.getRechargeBankResponses.get(transferPayActivity.bankTransferIndex).getData().get(i).getMax_quota());
        if(transferPayActivity.getRechargeBankResponses.get(transferPayActivity.bankTransferIndex).getData().get(i).isChoose()){
            holder.choose.setImageResource(R.mipmap.check_ok);
        } else {
            holder.choose.setImageResource(R.mipmap.check_none);
        }

        return view;
    }

    static class ViewHolder {
        @BindView(R.id.bank)
        TextView bank;
        @BindView(R.id.subbank)
        TextView subbank;
        @BindView(R.id.gathering_person)
        TextView gatheringPerson;
        @BindView(R.id.account)
        TextView account;
        @BindView(R.id.choose)
        ImageView choose;
        @BindView(R.id.exchangeRange)
        TextView exchangeRange;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
